
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    var SingleTon=(function(){
        function Tank(){
            this.dom=null;
            this.speed=0;
            this.color='';
            this.run=function(){}
        }
        var instance=null //保存实例化对象

        return {
           // getInstance:getInstance(){当对象的某个属性的值是个函数时，可以简写为属性(){}
           getInstance(){
            //if(instance){//if(/*如果已经实例化了一个对象*/){
                //return instance  //return /*return 已经实例化的那个对象，不再重新创建对象 */
            //}else{
                 //}else{
            //return /*创建一个新对象，返回*/}
                //return instance=new Tank()
            //}
           // return instance?instance:(instance=new Tank)
            return instance ||(instance=new Tank())

        }
            }
        })()

    var a =SingleTon.getInstance();
    var b =SingleTon.getInstance();
    var c =SingleTon .getInstance();
    console.log(a,b,c);
    console.log(a==b);
    console.log(a==c);
    console.log(b==c);

</script>